package controller;

import controller.trafficlights.*;
import controller.trafficlights.TrafficLight.TrafficLightState;
import simulator.enums.Direction;
import simulator.enums.LaneType;

public class Lane 
{
	private Direction _direction;
	private TrafficLight[] _lightsArray;
	
	public Lane(Direction direction)
	{
		_direction = direction;
		_lightsArray = new TrafficLight[8];
		_lightsArray[0] = new PedestrianLight(_direction, LaneType.SIDEWALK_RIGHTSIDE);
		_lightsArray[1] = new BikeLight(_direction, LaneType.BIKELANE);
		_lightsArray[2] = new BusLight(_direction, LaneType.BUSLANE);
		_lightsArray[3] = new CarLight(_direction, LaneType.CAR_RIGHT);
		_lightsArray[4] = new CarLight(_direction, LaneType.CAR_STRAIGHT);
		_lightsArray[5] = new CarLight(_direction, LaneType.CAR_LEFT);
		_lightsArray[6] = null; //Exit lane
		_lightsArray[7] = new PedestrianLight(_direction, LaneType.SIDEWALK_LEFTSIDE);
	}
	
	public void normalMode()
	{
		_lightsArray[0].changeState(TrafficLightState.red);
		_lightsArray[1].changeState(TrafficLightState.red);
		_lightsArray[2].changeState(TrafficLightState.red);
		_lightsArray[3].changeState(TrafficLightState.red);
		_lightsArray[4].changeState(TrafficLightState.red);
		_lightsArray[5].changeState(TrafficLightState.red);
		_lightsArray[7].changeState(TrafficLightState.red);
	}
	
	public void nightMode()
	{
		_lightsArray[0].changeState(TrafficLightState.off);
		_lightsArray[1].changeState(TrafficLightState.off);
		_lightsArray[2].changeState(TrafficLightState.off);
		_lightsArray[3].changeState(TrafficLightState.blink);
		_lightsArray[4].changeState(TrafficLightState.blink);
		_lightsArray[5].changeState(TrafficLightState.blink);
		_lightsArray[7].changeState(TrafficLightState.off);
	}
	
	public void morningMode()
	{
		_lightsArray[0].changeState(TrafficLightState.off);
		_lightsArray[1].changeState(TrafficLightState.off);
		_lightsArray[2].changeState(TrafficLightState.off);
		_lightsArray[3].changeState(TrafficLightState.off);
		_lightsArray[4].changeState(TrafficLightState.off);
		_lightsArray[5].changeState(TrafficLightState.off);
		_lightsArray[7].changeState(TrafficLightState.off);
	}
	
	public TrafficLight getTrafficLight(LaneType type)
	{
		return _lightsArray[type.getID()];
	}
}
